/**
 * 事件处理器
 * 
 * @author 烦得很
 */
public class EventHandlers {
    private PlayerEvent playerEvent = new PlayerEvent();
    public Object[] allGameLevel = new Object[10];

    public abstract static class EventIdAndType {
        public static int eventId = -1;
        public static int type = -1;
    }

    public interface AllEvent {
        public void onEvent(EventIdAndType e);
    }

    public PlayerEvent getPlayerEventInsatance() {
        return playerEvent;
    }

    /**
     * 玩家相关事件处理
     */
    public class PlayerEvent {
        /**
         * 玩家遇到的事件处理
         * 
         * @param position 玩家位置
         * @param level    等级
         * @param event    回调函数，具体实现事件
         * @throws Exception 关卡不存在
         */
        public void playerMoveEvent(int[] position,int level, AllEvent event) throws Exception {
            int index = -1;
            int eventId = -1;
            for (int i = 0; i < GameLevel1.mapEventAreaAndIndex.mapEventArea.length; i++) {
                for (int j = 0; j < GameLevel1.mapEventAreaAndIndex.mapEventArea[i].length; j++) {
                    int[] eventPosition = { GameLevel1.mapEventAreaAndIndex.mapEventArea[i][j][1],
                            GameLevel1.mapEventAreaAndIndex.mapEventArea[i][j][2] };
                    if (position.equals(eventPosition)) {
                        index = i;
                        eventId = GameLevel1.mapEventAreaAndIndex.mapEventArea[i][j][0];
                        break;
                    }
                }
            }
            if (index == -1) {
                return;
            } else {
                EventIdAndType.eventId = eventId;
                EventIdAndType.type = index;
            }
        }
    }
}